package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 评分点实体类
 * 对应数据库表：scoring_point
 *
 * 根据B-02-03-07简答题管理子模块设计文档实现
 * 管理简答题的评分点信息，支持多维度评分、权重分配和智能评分规则。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "scoring_point")
@Comment("评分点表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ScoringPoint {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 评分点唯一标识符
     */
    @NotBlank(message = "评分点ID不能为空")
    @Size(max = 50, message = "评分点ID长度不能超过50个字符")
    @Column(name = "point_id", nullable = false, length = 50, unique = true)
    private String pointId;

    /**
     * 关联的简答题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 评分点代码（用于关联和识别）
     */
    @NotBlank(message = "评分点代码不能为空")
    @Size(max = 32, message = "评分点代码长度不能超过32个字符")
    @Column(name = "point_code", nullable = false, length = 32)
    private String pointCode;

    /**
     * 评分点名称
     */
    @NotBlank(message = "评分点名称不能为空")
    @Size(max = 200, message = "评分点名称长度不能超过200个字符")
    @Column(name = "point_name", nullable = false, length = 200)
    private String pointName;

    /**
     * 评分点描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 评分点类型（CONTENT-内容评分，LOGIC-逻辑评分，FORMAT-格式评分，COMPREHENSIVE-综合评分）
     */
    @NotBlank(message = "评分点类型不能为空")
    @Size(max = 20, message = "评分点类型长度不能超过20个字符")
    @Column(name = "point_type", nullable = false, length = 20)
    private String pointType;

    /**
     * 评分点分类（KNOWLEDGE-知识点，SKILL-技能点，PROCESS-过程，RESULT-结果）
     */
    @Size(max = 20, message = "评分点分类长度不能超过20个字符")
    @Column(name = "point_category", length = 20)
    private String pointCategory;

    /**
     * 分值
     */
    @NotNull(message = "分值不能为空")
    @Column(name = "score_value", nullable = false, precision = 5, scale = 2)
    private BigDecimal scoreValue;

    /**
     * 权重（用于计算总分）
     */
    @NotNull(message = "权重不能为空")
    @Column(name = "weight", nullable = false, precision = 5, scale = 3)
    private BigDecimal weight;

    /**
     * 最大得分
     */
    @Column(name = "max_score", precision = 5, scale = 2)
    private BigDecimal maxScore;

    /**
     * 最小得分
     */
    @Column(name = "min_score", precision = 5, scale = 2)
    private BigDecimal minScore;

    /**
     * 步长（用于递增评分）
     */
    @Column(name = "score_step", precision = 5, scale = 2)
    private BigDecimal scoreStep;

    /**
     * 评分标准说明
     */
    @Column(name = "scoring_criteria", columnDefinition = "TEXT")
    private String scoringCriteria;

    /**
     * 详细评分规则
     */
    @Column(name = "scoring_rules", columnDefinition = "TEXT")
    private String scoringRules;

    /**
     * 关键词列表（用于智能评分，JSON格式）
     */
    @Column(name = "keywords", columnDefinition = "TEXT")
    private String keywords;

    /**
     * 必备关键词（必须包含的关键词）
     */
    @Column(name = "required_keywords", columnDefinition = "TEXT")
    private String requiredKeywords;

    /**
     * 禁忌关键词（不能包含的关键词）
     */
    @Column(name = "forbidden_keywords", columnDefinition = "TEXT")
    private String forbiddenKeywords;

    /**
     * 评分等级定义（JSON格式）
     */
    @Column(name = "scoring_levels", columnDefinition = "TEXT")
    private String scoringLevels;

    /**
     * 示例答案片段
     */
    @Column(name = "example_answer", columnDefinition = "TEXT")
    private String exampleAnswer;

    /**
     * 答案长度要求
     */
    @Size(max = 100, message = "答案长度要求长度不能超过100个字符")
    @Column(name = "answer_length_requirement", length = 100)
    private String answerLengthRequirement;

    /**
     * 是否为必需评分点
     */
    @NotNull(message = "必需标识不能为空")
    @Column(name = "is_required", nullable = false)
    private Boolean isRequired;

    /**
     * 是否支持部分得分
     */
    @NotNull(message = "部分得分设置不能为空")
    @Column(name = "allow_partial_score", nullable = false)
    private Boolean allowPartialScore;

    /**
     * 是否启用智能评分
     */
    @NotNull(message = "智能评分设置不能为空")
    @Column(name = "enable_smart_scoring", nullable = false)
    private Boolean enableSmartScoring;

    /**
     * 智能评分阈值（置信度阈值）
     */
    @Column(name = "smart_scoring_threshold", precision = 3, scale = 2)
    private BigDecimal smartScoringThreshold;

    /**
     * 是否自动评分
     */
    @NotNull(message = "自动评分设置不能为空")
    @Column(name = "auto_score", nullable = false)
    private Boolean autoScore;

    /**
     * 排序顺序
     */
    @NotNull(message = "排序顺序不能为空")
    @Column(name = "sort_order", nullable = false)
    private Integer sortOrder;

    /**
     * 评分点状态（ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃）
     */
    @NotBlank(message = "评分点状态不能为空")
    @Size(max = 20, message = "评分点状态长度不能超过20个字符")
    @Column(name = "point_status", nullable = false, length = 20)
    private String pointStatus;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 难度级别
     */
    @Column(name = "difficulty_level")
    private Integer difficultyLevel;

    /**
     * 知识点关联
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 能力要求（COMPREHENSION-理解，APPLICATION-应用，ANALYSIS-分析，SYNTHESIS-综合，EVALUATION-评价）
     */
    @Size(max = 20, message = "能力要求长度不能超过20个字符")
    @Column(name = "skill_requirement", length = 20)
    private String skillRequirement;

    /**
     * 评分提示信息
     */
    @Column(name = "scoring_hints", columnDefinition = "TEXT")
    private String scoringHints;

    /**
     * 常见错误示例
     */
    @Column(name = "common_errors", columnDefinition = "TEXT")
    private String commonErrors;

    /**
     * 评分校验规则
     */
    @Column(name = "validation_rules", columnDefinition = "TEXT")
    private String validationRules;

    /**
     * 评分统计信息（JSON格式）
     */
    @Column(name = "scoring_statistics", columnDefinition = "TEXT")
    private String scoringStatistics;

    /**
     * 版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version_number", nullable = false)
    private Integer versionNumber;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}